package com.lifeng.future;

/**
 * Created by lifeng on 2018/11/19.
 * 真实数据的包装
 */
public class FutureData implements MyData{
    private RealData realData;
    private boolean isReady = false;// 是否已经准备好

    public synchronized void setRealData(RealData realData){
        if (isReady){
            return;
        }
        this.realData = realData;
        isReady = true;
        notifyAll(); // RealData已经被注入到FutureData中了，通知getResult()方法
    }

    @Override
    public String getResult() throws InterruptedException {
        if(!isReady){
            wait();
        }
        return realData.getResult();
    }
}
